package com.limh.gobang.base

import android.content.Context
import android.content.DialogInterface
import android.os.Build
import android.os.Bundle
import android.support.v4.app.FragmentActivity
import android.view.WindowManager
import android.widget.Toast
import com.limh.gobang.R
import com.limh.gobang.view.CommDialog
import com.readystatesoftware.systembartint.SystemBarTintManager
import java.lang.ref.WeakReference


/**
 * @function：Activity基类
 * @author： limh
 * @date： 2018/4/22
 * Copyright @2018 Corpration Name
 */
abstract class BaseActivity : FragmentActivity() {
    private var tintManager: SystemBarTintManager? = null
    var context: Context? = null
    val TAG = this.javaClass.simpleName
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        context = WeakReference<Context>(this).get()
        findView()
        initViews()
        initDatas()
    }

    abstract fun findView()
    abstract fun initViews()
    abstract fun initDatas()

//    private fun initWindow(){
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
//            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
//            tintManager = SystemBarTintManager(this)
//            val status = context!!.resources.getColor(R.color.colorMain)
//            tintManager!!.setStatusBarTintColor(status)
//            tintManager!!.isStatusBarTintEnabled = true
//        }
//    }

    fun showToast(msg: String?) {
        runOnUiThread {
            Toast.makeText(context, msg!!, Toast.LENGTH_SHORT).show()
        }
    }

    fun showMsgDialog(title:String,msg: String) {
        val builder = CommDialog.Builder(this)
        builder.setTitle(title)
        builder.setMessage(msg)
        builder.setConfirm("确定", DialogInterface.OnClickListener { dialog, which ->
            dialog.dismiss()
        })
        builder.create().show()
    }
}